<template>
	<view style="user-select: text;">
		<sunMenu></sunMenu>
		<u-parse :content="content" class="parse"></u-parse> 
		<view style="height: 50rpx;"></view>
		<view class="footer">
			<text class="footer-text">© 2025 夏璽玥網路有限公司 版權所有 XIA AKOYA INC. All Rights Reserved. 統一編號90370186</text>
			 
		</view>
		<view style="height: 50rpx;"></view>
	</view>
</template>

<script>
	import sunMenu from '../../components/sun-menu/sun-menu.vue'
	import { getInformation, getProducts } from '@/api/api.js'
	export default {
		components: {
			sunMenu
		},
		data() {
			return {
				content: '',
				query:{
					noticeType: ''
				}, 
			}
		},
		onLoad(op) { 
			this.getList(op)
		},
		methods: {
			getList(e){
				this.query.noticeType = e.type
				this.query.activityId = e.activityId
				getInformation(this.query).then(res=>{  
					this.content = this.appendToVideoUrl(res.rows[0].noticeContent)
				}) 
			},
			appendToVideoUrl(content) {
				if (!content) return '';
				const screenWidth = window.innerWidth;
				const isMobile = screenWidth < 768;
				
				// ===================== 处理视频 =====================
				const videoRegex = /(<iframe\s+[^>]*)(>)/g;
				// 移动端：使用rpx单位，宽680rpx
				// PC端：使用px单位，宽700px
				const videoStyle = isMobile 
					? ' style="width: 680rpx;height: 400rpx;"'  // 移动端视频样式
					: ' style="width: 700px;height: 400px;"';   // PC端视频样式
				
				// 为视频添加样式
				content = content.replace(videoRegex, (match, p1, p2) => {
					return `${p1}${videoStyle}${p2}`;
				});
				
				// ===================== 处理图片 =====================
				const imgRegex = /(<img\s+[^>]*)(\/?>)/g;
				// 移动端：最大宽度680rpx，宽度100%自适应
				// PC端：最大宽度700px，宽度100%自适应
				const imgStyle = isMobile
					? ' style="width: 100%;"'  // 移动端图片样式
					: ' style="width: 100%;"';  // PC端图片样式�片样式
					
				// 为图片添加样式
				content = content.replace(imgRegex, (match, p1, p2) => {
					// 如果图片标签已经有style属性
					if (p1.includes('style="')) {
						// 在原有style基础上添加宽度限制
						return p1.replace(
							'style="', 
							`style="max-width: ${isMobile ? '680rpx' : '700px'};width: 100%;`
						) + p2;
					}
					// 如果没有style属性，直接添加新的style
					return `${p1}${imgStyle}${p2}`;
				});
				
				return content;
			},   
		}
	}
</script>
 
<style scoped>
	.parse {
		display: flex;
		justify-content: center;
		text-align: center;
		padding: 24rpx;
		max-width: 2400rpx;
		margin: 0 auto;
		background-color: #ffffff;
		border-radius: 16rpx;
		box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.03);
	}
	
	/* 添加商品展示相关样式 */
	.section-title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		text-align: center;
		margin: 40rpx 0;
		position: relative;
		padding-bottom: 20rpx;
	}
	
	.section-title::after {
		content: '';
		position: absolute;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		width: 80rpx;
		height: 4rpx;
		background: linear-gradient(90deg, #ff4d4f, #ff7875);
		border-radius: 2rpx;
	}

	.products-container {
		padding: 40rpx;
		max-width: 1400rpx;
		margin: 0 auto;
		margin-bottom: 80rpx;
		background-color: #ffffff;
		border-radius: 24rpx;
		box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
	}

	.products-grid {
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(300rpx, 1fr));
		gap: 32rpx;
		padding: 20rpx;
	}

	.product-card {
		background: #ffffff;
		border-radius: 20rpx;
		overflow: hidden;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
		transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
		border: 1px solid #f0f0f0;
	}

	.product-card:hover {
		transform: translateY(-6rpx);
		box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.12);
	}

	.product-image {
		width: 100%;
		height: 360rpx;
		object-fit: cover;
		transition: transform 0.3s ease;
	}

	.product-card:hover .product-image {
		transform: scale(1.05);
	}

	.product-info {
		padding: 24rpx;
		display: flex;
		flex-direction: column;
		gap: 12rpx;
		background: #fff;
	}

	.product-name {
		font-size: 28rpx;
		font-weight: 600;
		color: #333;
		line-height: 1.4;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.product-price {
		font-size: 32rpx;
		color: #ff4d4f;
		font-weight: bold;
		margin: 8rpx 0;
	}

	.item-spec {
		width: 100%;
		padding: 12rpx;
		border: 1px solid #ddd;
		border-radius: 8rpx;
		font-size: 26rpx;
		background-color: #fff;
		color: #333;
		cursor: pointer;
		transition: all 0.3s ease;
	}

	.item-spec:hover {
		border-color: #ff4d4f;
	}

	.item-spec:focus {
		outline: none;
		border-color: #ff4d4f;
		box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.1);
	}

	.item-spec-text {
		display: block;
		padding: 12rpx;
		font-size: 26rpx;
		color: #666;
		background-color: #f5f5f5;
		border-radius: 8rpx;
		text-align: center;
	}

	@media screen and (max-width: 768px) {
		.products-container {
			padding: 20rpx;
			margin: 0 16rpx 32rpx 16rpx;
			border-radius: 16rpx;
		}

		.products-grid {
			grid-template-columns: repeat(2, 1fr);
			gap: 16rpx;
			padding: 12rpx;
		}
		
		.product-image {
			height: 320rpx;
		}
		
		.product-info {
			padding: 16rpx;
		}
		
		.product-name {
			font-size: 24rpx;
		}
		
		.product-price {
			font-size: 28rpx;
			margin: 6rpx 0;
		}
		
		.item-spec, .item-spec-text {
			font-size: 24rpx;
			padding: 10rpx;
		}

		.section-title {
			font-size: 32rpx;
			margin: 24rpx 0;
		}
	}
</style>